<template>
  <div
      class="container"
      @mousemove="checkDistance"
      @mouseleave="isActive = false"
  >
    <!-- 触发区域指示 -->
    <div class="trigger-zone" :style="triggerStyle">

    </div>

    <!-- 面部 -->
    <div class="face">
      <!-- 左眼 -->
      <div class="eye left" :class="{ 'happy-eye': isActive }"></div>
      <!-- 右眼 -->
      <div class="eye right" :class="{ 'happy-eye': isActive }"></div>
      <!-- 嘴巴 -->
      <div class="mouth" :class="{ 'happy-mouth': isActive, 'sad-mouth': !isActive }"></div>

      <!-- 提示文字 -->
      <div class="hint" :class="{ active: isActive }">
        {{ isActive ? '😊 放这里可以变开心' : '😢 把我拖到这儿' }}
      </div>
    </div>

    <SolarSystem />
  </div>



</template>

<script setup>
import { ref, onMounted, computed } from 'vue'
import SolarSystem from '../components/SolarSystem.vue';

const isActive = ref(false)
const faceRect = ref({ x: 0, y: 0, width: 0, height: 0 })
const triggerRadius = 150 // 触发半径

// 获取面部元素位置
const updateFaceRect = () => {
  const face = document.querySelector('.face')
  const rect = face.getBoundingClientRect()
  faceRect.value = {
    x: rect.left + rect.width/2,
    y: rect.top + rect.height/2,
    width: rect.width,
    height: rect.height
  }
}

// 鼠标移动检测
const checkDistance = (e) => {
  const dx = e.clientX - faceRect.value.x
  const dy = e.clientY - faceRect.value.y
  const distance = Math.sqrt(dx*dx + dy*dy)
  isActive.value = distance < triggerRadius
}

// 触发区域样式
const triggerStyle = computed(() => ({
  width: `${triggerRadius*2}px`,
  height: `${triggerRadius*2}px`,
  left: `${faceRect.value.x - triggerRadius}px`,
  top: `${faceRect.value.y - triggerRadius}px`
}))

// 初始化及响应式更新
onMounted(() => {
  updateFaceRect()
  window.addEventListener('resize', updateFaceRect)
})
</script>

<style scoped>
.container {
  width: 100%;
  height: 100%;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

.face {
  position: relative;
  width: 300px;
  height: 300px;
  background: #ffd700;
  border-radius: 50%;
  transition: transform 0.3s ease;
  margin: 0 30px;
}

.face:hover {
  transform: scale(1.05);
}

.eye {
  position: absolute;
  width: 30px;
  height: 30px;
  background: #333;
  border-radius: 50%;
  top: 30%;
  transition: all 0.3s cubic-bezier(0.68, -0.55, 0.27, 1.55);
}

.left { left: 25%; }
.right { right: 25%; }

.happy-eye {
  height: 15px !important;
  border-radius: 15px !important;
}

.mouth {
  position: absolute;
  width: 90px;
  height: 45px;
  left: 50%;
  top: 65%;
  transform: translateX(-50%);
  border: 4px solid transparent;
  transition: all 0.4s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

.happy-mouth {
  border-radius: 0 0 80px 80px;
  border-bottom-width: 6px;
  border-bottom-color: #e74c3c;
  transform: translateX(-50%) scaleY(1.2);
}

.sad-mouth {
  border-radius: 80px 80px 0 0;
  border-top-width: 8px;
  border-top-color: #3498db;
  transform: translateX(-50%) scaleY(0.8);
}

.trigger-zone {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  transition: transform 0.3s ease;
}

.hint {
  position: absolute;
  bottom: -20%;
  left: 20%;
  font-size: 1.2em;
  color: #f8c1c1;
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.3s ease;
}

.hint.active {
  opacity: 1;
  transform: translateY(0);
  color: #2ecc71;
}

/* 微交互动画 */
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.trigger-zone {
  animation: bounce 3s ease-in-out infinite;
}
</style>